home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / Graphics / QuickDraw GX / GX->PostScript Sample / GXToPostScript / PostScriptFiles / TransformProcs.ps < prev   
Encoding:
Text File  |  2000-09-28  |  4.6 KB  |  193 lines  |  [TEXT/MPS ]

  1. %
  2. %    File:        TransformProcs.ps
  3. %
  4. %    Contains:    This file contains the procedures used for Skia transofrms. 
  5. %        These procedures are (so far) Portable PostScript.
  6. %
  7. %    Version:    Technology:    Quickdraw GX 1.1.x.
  8. %
  9. %    Copyright:    © 1991-7 by Apple Computer, Inc., all rights reserved.
  10. %
  11. %
  12.  
  13. %        File contains the following Procedures:
  14. %            MakeTrDict
  15. %            SetTr
  16. %            MapCTM
  17. %            QD2Clip
  18.  
  19. %
  20. %        Routine scales 6 mapping values by z.
  21. %            a b c d e f z ScaleMappingValues a/z b/z c/z e/z f/z
  22. %                    Note, z is an integer that is really a fract.
  23. /ScaleMappingValues {
  24.  
  25.     % Convert the fract into a float.
  26.     1073741824 div  % divide by 2^30 since fract is 2.30 bitwise
  27.     
  28.     % divide all 6 numbers by the scale.
  29.     7 1 roll
  30.     6 {
  31.         6 index div
  32.         6 -1 roll
  33.     } repeat
  34.  
  35.     7 -1 roll pop            % Get rid of z.
  36.  
  37. } Bdef
  38.  
  39.  
  40. %
  41. %        Routine takes 7 mapping values and makes a postscript matrix.
  42. %
  43. %            a b c d e f z MakMatrix matrix
  44. /MakMatrix {
  45.  
  46.     ScaleMappingValues
  47.     matrix astore
  48.  
  49. } Bdef
  50.  
  51.  
  52. %<FF>
  53. %        MapCTM:  Procedure maps the CTM by the specified mapping values.
  54. %
  55. %            a b c d e f MapCTM -
  56. %
  57. %                a b c d e f z:  Values for matrix [a/z b/z c/z d/z e/z f/z]
  58. /MapCTM {
  59.  
  60.     ScaleMappingValues                        % Fix the numbers.
  61.     ScratchMatrix astore                    % Make a matrix from the 6 values.
  62.     concat                                                % Concatonate it with the CTM.
  63.     CurrPat null ne {                            % If there is a pattern.
  64.         SynchPatMatrix                            % Synch up the new CTM with the pattern.
  65.     } if
  66.     
  67. } Bdef
  68.  
  69.  
  70.  
  71. %<FF>
  72. %
  73. %        Clipping dictionary.
  74. %            
  75. /ClipDict 5 dict dup 3 -1 roll Xdef begin        % Create a dictionary, name it ClipDict.
  76.  
  77.     % Framed means clip to the stroke-path (should be hairline).  Make sure we don't get limitcheck.
  78.     /Fr    {
  79.                 currentlinewidth                            % Save the current line width on the stack
  80.                 0 setlinewidth                                % Make it a hairline for the framed clip
  81.                 /strokepath 0 AvoidLimit            % Get the filled path of the framed object
  82.                 clip                                                    % Make it the current clip
  83.                 setlinewidth                                    % Restore the linewidth from saved value on the stack.
  84.             } Bdef
  85.     
  86.     % Inverse fill is current path + FullPath and then eoclip.   Make sure we don't get limitcheck.
  87.     /In {FullPath /eoclip 0 AvoidLimit} Bdef
  88.     
  89.     % even-odd is eoclip
  90.     /Eo {/eoclip 0 AvoidLimit} Bdef
  91.     
  92.     % Winding number fill is normal PostScript clip
  93.     /W {/clip 0 AvoidLimit} Bdef
  94.     
  95.     % no fill means clip everything out.
  96.     /No {
  97.                 newpath                    % Clear out whatever path was there
  98.                 EmptyPath                % Put an empty path there.
  99.                 clip
  100.                 
  101.             } Bdef
  102.         
  103. end                %ClipDict
  104.  
  105. %
  106. %    QD2Clip Operator.  Does all Skia clips.  Makes sure we have a new path afterwards.
  107. %
  108. %        fillKey QD2Clip -
  109. %
  110. %        fillKey:        A valid Skia fill key.
  111. %
  112. /QD2Clip {
  113.  
  114.     ClipDict exch get exec                    % Execute the clip procedure according to the fillKey.
  115.     newpath                                                    % We always want a new path afterwards.
  116.     
  117. } Bdef
  118.  
  119.  
  120.  
  121.  
  122. %<FF>
  123. %        The MakeTrDict proc:
  124. %
  125. %            Makes a dictionary out of the parts of a Skia transform.
  126. %
  127. %            clipGeom clipFill matrix MakeTrDict trDict
  128. %
  129. %                clipGeom:                    The procedure describing the clip shape's geometry.
  130. %                clipFill:                    The fill key for the clip shape.
  131. %                matrix:                        The matrix to use for this transform
  132. %                dict:                            The dictionary created by MakeTrDict
  133. %
  134. /MakeTrDict {
  135.                                                 
  136.     7 dict begin            % Create a dictionary, Make it current dict, leave on op stack.
  137.  
  138.         /Mapping Xdef            
  139.         /ClipFill Xdef
  140.         /ClipGeom Xdef
  141.  
  142.         /xTrans Mapping 4 get def                % Get Translation component of Mapping.
  143.         /yTrans Mapping 5 get def
  144.  
  145.         % Define the procedure to set the clip, make it do nothing if clip is full shape.
  146.         
  147.         /ClipGeom load 0 get /FullPath cvx eq ClipFill /Eo eq ClipFill /W eq or and not {
  148.             
  149.              /TrSetClip {ClipGeom ClipFill QD2Clip} BDef
  150.              /isSimpleTranslation false def                                    % Transform not simple if there's a clip.
  151.         
  152.         } {
  153.         
  154.             /TrSetClip {} def
  155.             
  156.             % Check to see if Mapping is a simple translation.
  157.             
  158.             Mapping aload pop pop pop        %     Stack is:    a b c d
  159.             
  160.             1 eq exch                % Stack is: a b d==1 c
  161.             0 eq and exch        % Stack is: a {c==0 && d==1} b
  162.             0 eq and exch        % Stack is: {b==0 && c==0 && d==1} a
  163.             1 eq and                % Stack is: {a==1 && b==0 && c==0 && d==1}
  164.             
  165.             /isSimpleTranslation  Xdef
  166.         
  167.         } ifelse
  168.  
  169.         currentdict            % Leave a copy of the dictionary on the stack.        
  170.     end
  171.  
  172. } Bdef
  173.  
  174.  
  175. %<FF>
  176. %        The SetTr proc:
  177. %
  178. %        Takes a transform dictionary and makes the graphics state reflect its contents.
  179. %
  180. %        trDict SetTr -
  181. %
  182. %            trDict:            A valid transform dictionary.  Usually created by MakeTrDict.
  183. %
  184. /SetTr {
  185.     begin                                % Put the transform dictionary at the top of the dictionary stack.
  186.     
  187.         Mapping concat        % Concatonate the transform's mapping with the CTM
  188.         TrSetClip                    % Set the clip.
  189.                             
  190.     end                                    % Remove the transform dictionary from the dictionary stack.
  191.  
  192. } Bdef
  193.